/**
 */
package ms.unicorn.dsl.unicornDSL.impl;

import java.util.Collection;

import ms.unicorn.dsl.unicornDSL.IdentifiedElement;
import ms.unicorn.dsl.unicornDSL.UnicornDSLPackage;
import ms.unicorn.dsl.unicornDSL.XExpression;
import ms.unicorn.dsl.unicornDSL.XForExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XFor Expression</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#getForVar <em>For Var</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#getCondition <em>Condition</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#getPostFors <em>Post Fors</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#isForEach <em>For Each</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#getList <em>List</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XForExpressionImpl#getBody <em>Body</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XForExpressionImpl extends XExpressionImpl implements XForExpression
{
  /**
   * The cached value of the '{@link #getForVar() <em>For Var</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getForVar()
   * @generated
   * @ordered
   */
  protected IdentifiedElement forVar;

  /**
   * The cached value of the '{@link #getCondition() <em>Condition</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCondition()
   * @generated
   * @ordered
   */
  protected XExpression condition;

  /**
   * The cached value of the '{@link #getPostFors() <em>Post Fors</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPostFors()
   * @generated
   * @ordered
   */
  protected EList<XExpression> postFors;

  /**
   * The default value of the '{@link #isForEach() <em>For Each</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isForEach()
   * @generated
   * @ordered
   */
  protected static final boolean FOR_EACH_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isForEach() <em>For Each</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isForEach()
   * @generated
   * @ordered
   */
  protected boolean forEach = FOR_EACH_EDEFAULT;

  /**
   * The cached value of the '{@link #getList() <em>List</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getList()
   * @generated
   * @ordered
   */
  protected XExpression list;

  /**
   * The cached value of the '{@link #getBody() <em>Body</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getBody()
   * @generated
   * @ordered
   */
  protected XExpression body;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected XForExpressionImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return UnicornDSLPackage.Literals.XFOR_EXPRESSION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public IdentifiedElement getForVar()
  {
    return forVar;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetForVar(IdentifiedElement newForVar, NotificationChain msgs)
  {
    IdentifiedElement oldForVar = forVar;
    forVar = newForVar;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR, oldForVar, newForVar);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setForVar(IdentifiedElement newForVar)
  {
    if (newForVar != forVar)
    {
      NotificationChain msgs = null;
      if (forVar != null)
        msgs = ((InternalEObject)forVar).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR, null, msgs);
      if (newForVar != null)
        msgs = ((InternalEObject)newForVar).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR, null, msgs);
      msgs = basicSetForVar(newForVar, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR, newForVar, newForVar));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getCondition()
  {
    return condition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetCondition(XExpression newCondition, NotificationChain msgs)
  {
    XExpression oldCondition = condition;
    condition = newCondition;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__CONDITION, oldCondition, newCondition);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setCondition(XExpression newCondition)
  {
    if (newCondition != condition)
    {
      NotificationChain msgs = null;
      if (condition != null)
        msgs = ((InternalEObject)condition).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__CONDITION, null, msgs);
      if (newCondition != null)
        msgs = ((InternalEObject)newCondition).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__CONDITION, null, msgs);
      msgs = basicSetCondition(newCondition, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__CONDITION, newCondition, newCondition));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<XExpression> getPostFors()
  {
    if (postFors == null)
    {
      postFors = new EObjectContainmentEList<XExpression>(XExpression.class, this, UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS);
    }
    return postFors;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isForEach()
  {
    return forEach;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setForEach(boolean newForEach)
  {
    boolean oldForEach = forEach;
    forEach = newForEach;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__FOR_EACH, oldForEach, forEach));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getList()
  {
    return list;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetList(XExpression newList, NotificationChain msgs)
  {
    XExpression oldList = list;
    list = newList;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__LIST, oldList, newList);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setList(XExpression newList)
  {
    if (newList != list)
    {
      NotificationChain msgs = null;
      if (list != null)
        msgs = ((InternalEObject)list).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__LIST, null, msgs);
      if (newList != null)
        msgs = ((InternalEObject)newList).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__LIST, null, msgs);
      msgs = basicSetList(newList, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__LIST, newList, newList));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getBody()
  {
    return body;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetBody(XExpression newBody, NotificationChain msgs)
  {
    XExpression oldBody = body;
    body = newBody;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__BODY, oldBody, newBody);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setBody(XExpression newBody)
  {
    if (newBody != body)
    {
      NotificationChain msgs = null;
      if (body != null)
        msgs = ((InternalEObject)body).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__BODY, null, msgs);
      if (newBody != null)
        msgs = ((InternalEObject)newBody).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XFOR_EXPRESSION__BODY, null, msgs);
      msgs = basicSetBody(newBody, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XFOR_EXPRESSION__BODY, newBody, newBody));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR:
        return basicSetForVar(null, msgs);
      case UnicornDSLPackage.XFOR_EXPRESSION__CONDITION:
        return basicSetCondition(null, msgs);
      case UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS:
        return ((InternalEList<?>)getPostFors()).basicRemove(otherEnd, msgs);
      case UnicornDSLPackage.XFOR_EXPRESSION__LIST:
        return basicSetList(null, msgs);
      case UnicornDSLPackage.XFOR_EXPRESSION__BODY:
        return basicSetBody(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR:
        return getForVar();
      case UnicornDSLPackage.XFOR_EXPRESSION__CONDITION:
        return getCondition();
      case UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS:
        return getPostFors();
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_EACH:
        return isForEach();
      case UnicornDSLPackage.XFOR_EXPRESSION__LIST:
        return getList();
      case UnicornDSLPackage.XFOR_EXPRESSION__BODY:
        return getBody();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR:
        setForVar((IdentifiedElement)newValue);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__CONDITION:
        setCondition((XExpression)newValue);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS:
        getPostFors().clear();
        getPostFors().addAll((Collection<? extends XExpression>)newValue);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_EACH:
        setForEach((Boolean)newValue);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__LIST:
        setList((XExpression)newValue);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__BODY:
        setBody((XExpression)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR:
        setForVar((IdentifiedElement)null);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__CONDITION:
        setCondition((XExpression)null);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS:
        getPostFors().clear();
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_EACH:
        setForEach(FOR_EACH_EDEFAULT);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__LIST:
        setList((XExpression)null);
        return;
      case UnicornDSLPackage.XFOR_EXPRESSION__BODY:
        setBody((XExpression)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_VAR:
        return forVar != null;
      case UnicornDSLPackage.XFOR_EXPRESSION__CONDITION:
        return condition != null;
      case UnicornDSLPackage.XFOR_EXPRESSION__POST_FORS:
        return postFors != null && !postFors.isEmpty();
      case UnicornDSLPackage.XFOR_EXPRESSION__FOR_EACH:
        return forEach != FOR_EACH_EDEFAULT;
      case UnicornDSLPackage.XFOR_EXPRESSION__LIST:
        return list != null;
      case UnicornDSLPackage.XFOR_EXPRESSION__BODY:
        return body != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (forEach: ");
    result.append(forEach);
    result.append(')');
    return result.toString();
  }

} //XForExpressionImpl
